function [a,P] =GetOpenNew(P,S,mode)
    B=S{1};

    P_X=P{1}(1);
    P_Y=P{1}(2);
    %P_theta=P{1}(3);
    %P_pace = P{5};

    B_X=B{1}(1);
    B_Y=B{1}(2);
    %angle=0;
    
    dist=sqrt((B_X-P_X)^2+(B_Y-P_Y)^2); % distance between player and ball
    %angle=atan2(B_Y-P_Y,B_X-P_X)/pi*180;    %compute the angle to the ball in degrees
    
    if(dist>30) % if the player is too far away from the ball, move towards it
        a = GoToBall(P,S,mode);
    else % if the player is reasonably close to the ball
        % determine the region of possible points to go to
        if(B_Y > P_Y)
            Max_Y = B_Y;
            Min_Y = max(-30, B_Y-10);
        else
            Max_Y = min(30, B_Y + 10);
            Min_Y = B_Y;
        end
        
        Max_X = min(60,B_X + 10);
        Min_X = max(-60, B_X - 10);
        
        min_distance = -1;
        distances = zeros(1,5);
        % iterate over each point in the feasible region to find the one
        % that maximizes the distance to the closest opponent
        for X = Min_X:Max_X
            for Y = Min_Y:Max_Y
                % relative distance from each player to the ball
                for k = 7:11,
                    Pk = S{k};
                    Pk_X=Pk{1}(1);
                    Pk_Y=Pk{1}(2);
                    
                    Pk_R=sqrt((B_Y-Pk_Y)^2+(B_X-Pk_X)^2);  % relative distance to the ball
                    distances(k-6) = Pk_R;
                end
                
                current_min = min(distances);
                if(current_min > min_distance)
                    min_distance = current_min;
                    Target_X = X;
                    Target_Y = Y;
                end    
            end
        end
        
        [a,P] = GoToLocation(P,S,mode, Target_X, Target_Y);
    end
    
end